package cn.easybuy.service.product;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.easybuy.entity.Product;
import cn.easybuy.mapper.ProductMapper;

/**
 * 商品的业务类
 */
@Service
public class ProductServiceImpl implements ProductService {
	
	@Autowired
	private ProductMapper productMapper;

	@Override
	public boolean add(Product product) {
		Integer count=0;
		count=productMapper.addProduct(product);
		return count>0;
	}

	@Override
	public boolean update(Product product) {
		Integer count=0;
		count=productMapper.updateProduct(product);
		return count>0;
	}

	@Override
	public boolean deleteProductById(Integer productId) {
		Integer count=0;
		count=productMapper.deleteProduct(productId);
		return count>0;
	}

	@Override
	public Product getProductById(Integer productId) {
		Product product=null;
		product=productMapper.getProductById(productId);
		return product;
	}

	@Override
	public List<Product> getProductList(Integer currentPageNo,Integer pageSize,String proName, Integer categoryId, Integer level) {
		List<Product> productList=null;
		productList=productMapper.getProductListByName_level(currentPageNo,pageSize,proName,categoryId);
		return productList;
	}

	@Override
	public int count(String proName,Integer categoryId, Integer level) {
		Integer count=0;
		count=productMapper.getProductCount(proName,categoryId);
		return count;
	}

	@Override
	public boolean updateStock(Integer productId, Integer stock) {
		Integer count=0;
		count=productMapper.updateStock(productId,stock);
		return count>0;
	}
   
}
